const fs = require("fs");
const cheerio = require("cheerio");
const { indexName, crawlerMap } = require("../../config");
const TurndownService = require("turndown");
const {
  writeFileSync,
  fetchHtml,
  typeOf,
  getHomeFeatures,
  fetch,
  getAllNames,
} = require("../../utils");
const turndownService = new TurndownService({
  headingStyle: "atx", // 标题样式。	setext or atx    默认：setext
  // hr: "", //Any Thematic break    默认：* * *
  bulletListMarker: "-", //-, +, or *    默认：*
  codeBlockStyle: "fenced", //缩进或围起来。 indented or fenced    默认：indented（如果使用fenced围起来，vuepress不识别console代码高亮语言而一直在控制台打印Language does not exist: console）
  // fence: "", //``` or ~~~    默认：```
  // emDelimiter: "", //_ or *    默认：_
  // strongDelimiter: "", //** or __    默认：**
  // linkStyle: "", //内联或引用。  inlined or referenced    默认：inlined
  // linkReferenceStyle: "", //完整, 折叠或快捷方式。 full, collapsed, or shortcut    默认：full
  // preformattedCode: "", //false or true    默认：false
});

const htmlStr = `
<div>
<pre>
<code class="hljs language-ini copyable" lang="ini">
const <span class="hljs-attr">re</span> = /\d+/g<span class="hljs-comment">;</span>
<span class="copy-code-btn"><b>复制代码</b></span>
<span class="copy-code-btn"><b>复制代码1</b></span>
<span class="copy-code-btn"><b>复制代码</b></span>
</code>
</pre>
</div>
`;

const $ = cheerio.load(htmlStr);
// const $currHtml = $(htmlStr).find(".copy-code-btn").remove().parent();
const currHtml = $(htmlStr);
const remove = $(htmlStr).find(".copy-code-btn").remove();
// console.log(currHtml.text(), remove.text(), "test-----------------\n");
// console.log($currHtml, "currHtml---------------------");

// var dataId = "666007";
// // Put the markup in a new container
// var $currentHtml = $("<div>").append($("#edNew-body.apply-jHtmlArea").val());
// // .find() will now be able to search through all the markup you added
// $currentHtml.find(".multimedia_" + dataId).remove();
// // .html() will now give you back all the markup (though modified)
// $("#edNew-body.apply-jHtmlArea").val($currentHtml.html());

// function delFindNode(par, ".copy-code-btn"){

// }
// delFindNode("pre", ".copy-code-btn")

function delFindNode($, parHtml, seltor) {
  const findHtmls = [];
  $(parHtml)
    .not(seltor)
    .each((i, el) => {
      findHtmls.push($(el).text());
    });
  // const reg = new RegExp(Array.from(new Set(findHtmls)).join("|"), "g");
  // console.log(reg, "tars--------------\n");
  // return parHtml.replace(reg, "");
  console.log(findHtmls, "findHtmls------------");
}
const html = delFindNode($, htmlStr, ".copy-code-btn");
// console.log(html, "tarHtml------------");

// const args = process.argv;
// console.log(args.slice(2), "process-----------------\n");
// console.log(Object.keys(crawlerMap), "names-----------");
// writeFileSync("scripts/temp.js", process.toString());
// console.log(process.argv, "argv--------------");

// fetch("GET", "https://www.runoob.com/jquery/jquery-slide.html").then((res) => {
// https://www.runoob.com/juquery/jquery-intro.html
// https://www.runoob.com/jquery/jquery-intro.html
// fetch("GET", "https://www.runoob.com/jquery/jquery-intro.html").then((res) => {
//   console.log(res, "res--------------------");
// });

// $("#rmv").click(function (e) {
//   e.preventDefault();
//   var dataId = "666007";

//   // Put the markup in a new container
//   var $currentHtml = $("<div>").append($("#sub").val());

//   // .find() will now be able to search through all the markup you added
//   $currentHtml.find(".multimedia_" + dataId).remove();

//   // .html() will now give you back all the markup (though modified)
//   $("#sub").val($currentHtml.html());
// });

// function delNode(html, seltor) {
//   var $currentHtml = $(html).append($("#sub").val("fanlichuan"));

//   // .find() will now be able to search through all the markup you added
//   $currentHtml.find(seltor).remove();

//   // .html() will now give you back all the markup (though modified)
//   $("#sub").val($currentHtml.html());
//   console.log($("#sub").val($currentHtml.html()).html(), "html-----------");
// }
// const html = delNode(htmlStr, ".copy-code-btn");
// // console.log(html, "html---------------");
